<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    * {
        margin: 0;
        padding: 0;
    }

    .box {
        position: relative;
        width: 490px;
        height: 170px;
        padding: 10px;
        margin: 50px auto;
        border: 1px solid #000000;

    }

    .box>.box1 {
        position: relative;
        height: 100%;
        overflow: hidden;

    }

    .box>.box1>span {
        display: none;
        position: absolute;
        top: 50%;
        transform: translateY(-50%);
        width: 20px;
        height: 20px;
        background-color: rgba(0, 0, 0, .3);
        color: #fff;
        text-align: center;
        line-height: 20px;
        cursor: pointer;
    }

    .box>.box1>span:hover {
        background-color: rgba(0, 0, 0, .5);
    }

    .box>.box1>span#left {
        left: 0;
        border-top-right-radius: 20px;
        border-bottom-right-radius: 20px;
    }

    .box>.box1>span#right {
        right: 0;
        border-top-left-radius: 20px;
        border-bottom-left-radius: 20px;
    }

    .box>.box1>ul {
        position: absolute;
        top: 0px;
        left: 0;
        width: 500%;
        height: 100%;
        list-style: none;

    }

    .box>.box1>ul>li>img {

        /* 清除上下间距 */
        vertical-align: top;
    }

    .box>.box1>ul>li {
        float: left;
    }

    .box>ol {
        position: absolute;
        bottom: 15px;
        left: 50%;
        transform: translateX(-50%);
        list-style: none;
    }

    .box>ol>li {
        height: 20px;
        width: 20px;
        float: left;
        margin-left: 5px;
        background-color: #fff;
        text-align: center;
        line-height: 20px;
        cursor: pointer;
    }

    .box>ol>li:nth-child(1) {
        margin-left: 0;
    }
</style>
<script>
    window.onload = function () {
        function $(selecter) {
            return document.querySelector(selecter)
        }

        var ollis = document.querySelectorAll('ol>li');
        var uls = document.querySelector('ul');
        var target = 0; //目标值
        var leader = 0; //步长

        //对ol下的li循环遍历，注册事件
        ollis.forEach((item, index) => {
            item.onmouseover = function () {
                ollis.forEach(item => {
                    item.style.background = '';
                })
                this.style.background = 'orange';
                //计算目标值
                target = -index * 490
                //控制  点击的次数
                clickNum = index
            }

        })
        setInterval(() => {
            leader = leader + (target - leader) / 10
            uls.style.left = leader + 'px'
        }, 30)



        //轮播图两边的span
        function show(select) {
            document.querySelector(select).style.display = 'block'
        }
        function hide(selecter) {
            document.querySelector(selecter).style.display = 'none'
        }
        $('.box').onmouseover = function () {
            show('#left')
            show('#right')
        }
        $('.box').onmouseout = function () {
            hide('#left')
            hide('#right')
        }
        // 声明一个计数器
        var clickNum = 0
        // 点击左侧按钮
        $('#right').onclick = function () {
            if (target > -4 * 490) {
                clickNum++
                target = -clickNum * 490
            }
            // 让指示器 添加样式
            ollis.forEach(item => {
                item.style.background = ''
            })
            ollis[clickNum].style.background = 'orange'
        }
        // 右边按钮点击
        $('#left').onclick = function () {
            if (target < 0) {
                clickNum--
                target = -clickNum * 490
            }
            // 让指示器 添加样式
            ollis.forEach(item => {
                item.style.background = ''
            })
            ollis[clickNum].style.background = 'orange'

        }





    }
</script>

<body>
    <div class="box">
        <div class="box1">
            <ul>
                <li><img src="./15轮播图/imgs/01.jpg" alt=""></li>
                <li><img src="./15轮播图/imgs/02.jpg" alt=""></li>
                <li><img src="./15轮播图/imgs/03.jpg" alt=""></li>
                <li><img src="./15轮播图/imgs/04.jpg" alt=""></li>
                <li><img src="./15轮播图/imgs/05.jpg" alt=""></li>
            </ul>
            <span id="left">&lt;</span>
            <span id="right">&gt;</span>
        </div>

        <ol>
            <li style="background-color: orange;">1</li>
            <li>2</li>
            <li>3</li>
            <li>4</li>
            <li>5</li>
        </ol>
    </div>
</body>

</html>